package Euler23;

import java.util.*;
import ReusableCode.MathFunctions;

public class AbundantSums {
	public static void main(String[] args) {
		List<Integer> abundants = new ArrayList<Integer>();
		Map<Integer, Boolean> sums = new HashMap<Integer, Boolean>();
		long sum = 0;
		
		//Get all abundant numbers.
		for(int i = 1; i < 28123; i++)
		{
			if(MathFunctions.isAbundant(i))
			{
				abundants.add(i);
			}
		}
		
		//Get all numbers under 28123 that are the sum of 2 abundants.
		for(int i = 0; i < abundants.size(); i++)
		{
			for(int j = 0; j < (abundants.size()/2)+1; j++)
			{
				if((abundants.get(i)+abundants.get(j)) < 28123)
				{
					sums.put(abundants.get(i)+abundants.get(j), true);
				}
				else
				{
					break;
				}
			}
		}
		
		//Get the sum of all numbers that are not the sum of 2 abundants.
		for(int i = 1; i < 28123; i++)
		{
			if(!sums.containsKey(i))
			{
				sum += i;
			}
		}
		
		System.out.println(sum);
	}
}
